//
//  ModifyNameController.m
//  easystudy
//
//  Created by kane on 15/6/8.
//  Copyright (c) 2015年 kane. All rights reserved.
//

#import "ModifyNameController.h"

@interface ModifyNameController ()
{
    __weak IBOutlet UITextField *_usernameTF;
}

@end

@implementation ModifyNameController

- (void)viewDidLoad {
    [super viewDidLoad];
    _usernameTF.text = [UserEntity sharedUser].NickName;
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - User Actions

- (IBAction)backBtnPressed:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

- (IBAction)commitBtnPressed:(id)sender {
    [self.view endEditing:YES];
    if (_usernameTF.text.length == 0) {
        [self.view makeToast:@"请输入昵称"];
        return;
    }
    NSDictionary *params = @{@"mobile":[UserEntity sharedUser].MobilePhone,@"name":_usernameTF.text};
    [WebService modifyNickName:params WithBlock:^(id result, NSError *error) {
        if (!error) {
            if ([result[@"result"] intValue] == 1) {
                [UserEntity sharedUser].NickName = _usernameTF.text;
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:result[@"message"] delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                [alert show];
            }
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络连接失败,请检查网络" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
    }];
}

@end
